package com.ruan.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruan.mapper.LeaveTypeMapper;
import com.ruan.pojo.LeaveType;
import com.ruan.service.LeaveTypeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class LeaveTypeServiceImpl extends ServiceImpl<LeaveTypeMapper, LeaveType> implements LeaveTypeService {

    @Resource
    private LeaveTypeMapper leaveTypeMapper;

    /**
     * 获得请假类型列表
     * @return
     */
    @Override
    public List<LeaveType> getLeaveType() {
        List<LeaveType> leaveTypeList = leaveTypeMapper.selectList(null);
        return leaveTypeList;
    }

    /**
     * 禁用请假事由
     * @param id 事由id
     */
    @Override
    public void stopType(Integer id) {
        LeaveType leaveType = leaveTypeMapper.selectById(id);
        leaveType.setStatus("禁用");
        leaveTypeMapper.updateById(leaveType);
    }

    /**
     * 启用请假事由
     * @param id 事由id
     */
    @Override
    public void startType(Integer id) {
        LeaveType leaveType = leaveTypeMapper.selectById(id);
        leaveType.setStatus("启用");
        leaveTypeMapper.updateById(leaveType);
    }
}
